package com.dynamic.sync.toolkit.mongo.property;

import com.dynamic.sync.toolkit.EnvType;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author ZonLen since on 2021/6/18 下午5:08
 */
@Component
public class MongoPropertyManager {

  @Autowired
  private List<EnvMongoProperties> mongoPropertiesList;

  private EnvMongoProperties mongoProperties(EnvType envType) {
    for (EnvMongoProperties mongoProperties : mongoPropertiesList) {
      if (mongoProperties.envType() == envType) {
        return mongoProperties;
      }
    }
    throw new RuntimeException("环境未配置");
  }

  public String database(EnvType envType){
    return mongoProperties(envType).getDatabase();
  }

  public String uri(EnvType envType){
    return mongoProperties(envType).getUri();
  }


}
